﻿
using KinonekoSoftware.CodariaDB.Documents.Theories.Elements;

#if WINDOWS

using System.Windows.Controls;

#else

using Avalonia.Controls;

#endif

namespace KinonekoSoftware.Studio.Models.Theories
{
    public class TheoryOfElementPresenter : ObservableObject
    {
        private Dock _placement;
        
        public static TheoryOfElementPresenter Select(Element element, bool placement)
        {
            var p = new TheoryOfElementPresenter
            {
                TargetObject = element,
            };

            p.SetPlacement(placement);
            return p;
        }
        
        public static TheoryOfElementPresenter Select(Element element)
        {
            var p = new TheoryOfElementPresenter
            {
                TargetObject = element,
            };

            p.SetPlacement(false);
            return p;
        }

        public void RaiseUpdates()
        {
            RaiseUpdated(nameof(Image));
            RaiseUpdated(nameof(Icon));
            RaiseUpdated(nameof(Intro));
            RaiseUpdated(nameof(Name));
            RaiseUpdated(nameof(Foreground));
            RaiseUpdated(nameof(Background));
        }
        
        internal void SetPlacement(bool value)
        {
            Placement = value ? Dock.Left : Dock.Right;
        }
        
        public required Element TargetObject { get; init; }

        public string Id => TargetObject.Id;
        
        public string Image
        {
            get => TargetObject.Image;
            set
            {
                TargetObject.Image = value;
                RaiseUpdated();
            }
        }
        
        public string Icon
        {
            get => TargetObject.Icon;
            set
            {
                TargetObject.Icon = value;
                RaiseUpdated();
            }
        }

        public string Name
        {
            get => TargetObject.Name;
            set
            {
                TargetObject.Name = value;
                RaiseUpdated();
            }
        }

        public string Intro
        {
            get => TargetObject.Intro;
            set
            {
                TargetObject.Intro = value;
                RaiseUpdated();
            }
        }

        public string Foreground
        {
            get => TargetObject.Foreground;
            set
            {
                TargetObject.Foreground = value;
                RaiseUpdated();
            }
        }
        
        public string Background
        {
            get => TargetObject.Background;
            set
            {
                TargetObject.Background = value;
                RaiseUpdated();
            }
        }
        
        public Dock Placement
        {
            get => _placement;
            set => SetValue(ref _placement, value);
        }
    }
}